﻿// -----------------------------------------------------------------------
// <copyright file="Errors.cs" company="">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace BasicFrameworkDemo.Utility
{
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Xml;
    using System.Configuration;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class SystemErrors
    {
        private static readonly SystemErrors SystemErrorsInstance;

        private SystemErrors()
        {

        }

        public Dictionary<string, string> ErrorsDictionary
        {
            get
            {
                return errorsDictionary;
            }
        }

        public static SystemErrors GetInstance()
        {
            return SystemErrorsInstance ?? new SystemErrors();
        }

        /// <summary>
        /// error dictionary
        /// </summary>
        /// Creator:LiLei
        /// CreationDate:7/9/2012 4:55 PM
        /// Modify:
        /// ModifyDate:
        /// ----------------------------------------------------------------------------------------
        private static  Dictionary<string, string> errorsDictionary;

        /// <summary>
        /// Configs this instance.
        /// </summary>
        /// Creator:LiLei
        /// CreationDate:7/9/2012 4:55 PM
        /// Modify:
        /// ModifyDate:
        /// ----------------------------------------------------------------------------------------
        public void Config()
        {
            var xmlDoc = new XmlDocument();
            xmlDoc.Load(string.Format("{0}/{1}", AppDomain.CurrentDomain.BaseDirectory, SystemConfig.ErrorsConfigFilePath));

            var xmlParent = xmlDoc.SelectSingleNode(SystemConfig.ErrorsConfigFileRootNodeName);
            if (xmlParent == null)
            {
                return;
            }

            var childNodes = xmlParent.SelectNodes(SystemConfig.ErrorsConfigFileChildNodeName);
            if (childNodes.IsNullOrEmpty())
            {
                return;
            }

            errorsDictionary = new Dictionary<string, string>();
            foreach (XmlNode childNode in childNodes)
            {
                errorsDictionary.Add(childNode.ChildNodes[0].InnerText,childNode.ChildNodes[1].InnerText);
            }

        }
    }
}
